/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ExtratoUi.java
 *
 * Created on 23/12/2011, 13:35:43
 */
package br.com.bancofloripa.view;

import br.com.bancofloripa.controller.ExtratoController;
import java.awt.event.KeyEvent;

/**
 *
 * @author carlos
 */
public class ExtratoUi extends javax.swing.JInternalFrame {
    
    ExtratoController ec = new ExtratoController();
    private String tipo;

    /** Creates new form ExtratoUi */
    public ExtratoUi() {
        initComponents();
        jRBSimples1.setSelected(true);
        this.tipo = "simples";
        this.jRBOuro1.setSelected(false);
        this.jRBPoup1.setSelected(false);
        ec.atualizaTabela(ec.montandoList(tipo), jTable1);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        tfBusca = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();
        jRBSimples1 = new javax.swing.JRadioButton();
        jRBOuro1 = new javax.swing.JRadioButton();
        jRBPoup1 = new javax.swing.JRadioButton();
        jbBusca = new javax.swing.JButton();

        setMaximizable(true);
        setResizable(true);

        tfBusca.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tfBuscaKeyPressed(evt);
            }
        });

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null}
            },
            new String [] {
                "Conta", "Agência", "Titular", "Saldo", "Limite", "Juros"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTable1MouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jTable1);
        jTable1.getColumnModel().getColumn(5).setMinWidth(70);
        jTable1.getColumnModel().getColumn(5).setMaxWidth(70);

        jLabel1.setText("Cliente");

        jRBSimples1.setText("Simples");
        jRBSimples1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRBSimples1ActionPerformed(evt);
            }
        });

        jRBOuro1.setText("Ouro");
        jRBOuro1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRBOuro1ActionPerformed(evt);
            }
        });

        jRBPoup1.setText("Poupança");
        jRBPoup1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRBPoup1ActionPerformed(evt);
            }
        });

        jbBusca.setText("Buscar");
        jbBusca.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbBuscaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jScrollPane1)
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(tfBusca, javax.swing.GroupLayout.PREFERRED_SIZE, 560, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jbBusca)
                        .addContainerGap(28, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jRBSimples1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jRBOuro1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jRBPoup1)
                        .addGap(258, 258, 258))))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(12, 12, 12)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jRBSimples1)
                    .addComponent(jRBOuro1)
                    .addComponent(jRBPoup1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tfBusca, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1)
                    .addComponent(jbBusca))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 267, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(12, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void tfBuscaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tfBuscaKeyPressed
     
    }//GEN-LAST:event_tfBuscaKeyPressed

    private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked
        ec = new ExtratoController();
        ec.getClique(evt, jTable1, tfBusca);
    }//GEN-LAST:event_jTable1MouseClicked

    private void jRBSimples1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRBSimples1ActionPerformed
        String nome = this.tfBusca.getText();
        if (nome == null){
            nome = "";
        }        
        this.tipo = "simples";
        this.jRBOuro1.setSelected(false);
        this.jRBPoup1.setSelected(false);
        ec.atualizaTabela(ec.montandoList(nome, tipo), jTable1);
    }//GEN-LAST:event_jRBSimples1ActionPerformed

    private void jRBOuro1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRBOuro1ActionPerformed
        String nome = this.tfBusca.getText();
        if (nome == null){
            nome = "";
        }
        this.tipo = "ouro";
        this.jRBSimples1.setSelected(false);
        this.jRBPoup1.setSelected(false);
        ec.atualizaTabela(ec.montandoList(nome, tipo), jTable1);
    }//GEN-LAST:event_jRBOuro1ActionPerformed

    private void jRBPoup1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRBPoup1ActionPerformed
        String nome = this.tfBusca.getText();
        if (nome == null){
            nome = "";
        }
        this.tipo = "poup";
        this.jRBOuro1.setSelected(false);
        this.jRBSimples1.setSelected(false);
        ec.atualizaTabela(ec.montandoList(nome, tipo), jTable1);
    }//GEN-LAST:event_jRBPoup1ActionPerformed

    private void jbBuscaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbBuscaActionPerformed
        String nome = this.tfBusca.getText(); 
//        if(this.tipo.equalsIgnoreCase("simples")){
//            ec.atualizaTabela(  ec.montandoListSimples(nome), jTable1 );
//        } else if (this.tipo.equalsIgnoreCase("ouro")){
//            ec.atualizaTabela(  ec.montandoListOuro(nome), jTable1 );
//        } else {
//            ec.atualizaTabela(  ec.montandoListPoup(nome), jTable1 );
//        }
        ec.atualizaTabela(ec.montandoList(nome, tipo), jTable1);
    }//GEN-LAST:event_jbBuscaActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JRadioButton jRBOuro1;
    private javax.swing.JRadioButton jRBPoup1;
    private javax.swing.JRadioButton jRBSimples1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JButton jbBusca;
    private javax.swing.JTextField tfBusca;
    // End of variables declaration//GEN-END:variables



}
